import { defineStore } from 'pinia';
import { useProjectStore } from './project';
import { companysData, exhibitionData } from '@/api/templates/templates';
const store = useProjectStore();
export const usetmplate8Store = defineStore('usetmplate6Store', {
  state: () => ({
    isDrawer: false,
    persist: true,
    unitIndex: -1,
    isSelectDrawer: false,
    isDailog: false,
    exhibtsName: '',
    science: {},
    scrollNum: { show: false, number: 0 },
    routeName: '',
    scrollIndex: -1,
    scrollNumber: 0,
    isFiexd: false,
    routerTitle: '',
    ActiveIndex: -1,
    myPramas: {
      value: '',
      typeId: -1,
      ageId: [-1],
      levelId: -1,
      ModuleId: 1,
      CompanyId: -1,
      pageNo: 1,
      pageSize: 12,
      id: 0, //store.childModel.id,
    },
    myPramasWap: {
      value: '',
      typeId: -1,
      ageId: [-1],
      levelId: -1,
      ModuleId: 1,
      CompanyId: -1,
      pageNo: 1,
      pageSize: 8,
      id: 0, //store.childModel.id,
    },
    total: 0,
    list: [],
  }),
  actions: {
    setIsDrawer(boolean: boolean) {
      this.isDrawer = boolean;
    },
    setUnitIndex(index: number) {
      this.unitIndex = index;
    },
    async init() {
      try {
        // 年代id需要以数组的方式进行上传，所以进行处理
        let { data } = await exhibitionData(localStorage.getItem('projectId'), {
          ...this.myPramas,
          ageId: this.myPramas.ageId[this.myPramas.ageId.length - 1],
        });

        this.total = data.total;
        this.list = data.data;
        console.log(this.total);
      } catch {
        console.log('shibia');
      }
    },
    async initWap() {
      try {
        // 年代id需要以数组的方式进行上传，所以进行处理
        console.log(this.myPramasWap.ageId, this.myPramasWap.ageId[this.myPramasWap.ageId.length - 1]);

        let { data } = await exhibitionData(localStorage.getItem('projectId'), {
          ...this.myPramasWap,
          ageId: this.myPramasWap.ageId[this.myPramasWap.ageId.length - 1],
        });

        this.total = data.total;
        this.list = data.data;
        console.log(this.total);
      } catch {
        console.log('shibia');
      }
    },
    clearParamsId() {
      this.myPramas.id = 0;
    },
    clearParams() {
      this.myPramas = {
        value: '',
        typeId: -1,
        ageId: [-1],
        levelId: -1,
        ModuleId: 1,
        CompanyId: -1,
        pageNo: 1,
        pageSize: 12,
        id: 0, //store.childModel.id,
      };

      this.init();
    },
    clearParamsWap() {
      this.myPramasWap = {
        value: '',
        typeId: -1,
        ageId: [-1],
        levelId: -1,
        ModuleId: 1,
        CompanyId: -1,
        pageNo: 1,
        pageSize: 8,
        id: 0, //store.childModel.id,
      };
      this.initWap();
    },
  },
  persist: true,
});
// function exhibitionData(arg0: string, myPramas: any): { data: any } | PromiseLike<{ data: any }> {
//   throw new Error('Function not implemented.');
// }
